package com.bootdo.put.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.put.domain.PutStorageDO;
import com.bootdo.put.service.PutStorageService;
import com.bootdo.common.domain.DictDO;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 入库单
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-04-24 11:50:15
 */
 
@Controller
@RequestMapping("/put/putStorage")
public class PutStorageController {
	
	@Autowired
	private PutStorageService putStorageService;
	
	@GetMapping()
	String PutStorage(){
	    return "put/putStorage/putStorage";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<PutStorageDO> putStorageList = putStorageService.list(query);
		int total = putStorageService.count(query);
		PageUtils pageUtils = new PageUtils(putStorageList, total);
		return pageUtils;
	}
	
	@ResponseBody
	@GetMapping("/status")
	public List<PutStorageDO> listStatus() {
		return putStorageService.listStatus();
	};
	
	@ResponseBody
	@GetMapping("/list/{status}")
	public List<PutStorageDO> listByType(@PathVariable("status") String status) {
		// 查询列表数据
		Map<String, Object> map = new HashMap<>(16);
		map.put("status", status);
		List<PutStorageDO> statusList = putStorageService.list(map);
		return statusList;
	}

	@GetMapping("/add")
	String add(){
	    return "put/putStorage/add";
	}

	@ResponseBody
	@GetMapping("/edit/updates/{putId}")
	String edit(@PathVariable("putId") Long putId,Model model){
		PutStorageDO putStorage = putStorageService.get(putId);
		model.addAttribute("putStorage", putStorage);
	    return "put/putStorage/updates/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save/updates/")
	public R save( PutStorageDO putStorage){
		if(putStorageService.save(putStorage)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update/updates/")
	public R update( PutStorageDO putStorage){
		putStorageService.update(putStorage);
		return R.ok();
	}
	
	
	
//	/**
//	 * 删除
//	 */
//	@PostMapping( "/remove")
//	@ResponseBody
//	public R remove( Long putId){
//		if(putStorageService.remove(putId)>0){
//		return R.ok();
//		}
//		return R.error();
//	}
//	
//	/**
//	 * 删除
//	 */
//	@PostMapping( "/batchRemove")
//	@ResponseBody
//	public R remove(@RequestParam("ids[]") Long[] putIds){
//		putStorageService.batchRemove(putIds);
//		return R.ok();
//	}
	
}
